#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4 + 10;
int arr[N];
int n,m;
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	/*while (m--) {
		next_permutation(arr + 1, arr + n + 1);
	}*/
	for (int i = 1; i <= m; i++) {
		int k = n;
		while (arr[k - 1] > arr[k])k--;
		int t = k;
		while (arr[t] > arr[k - 1])t++;
		swap(arr[t - 1], arr[k - 1]);
		reverse(arr + k, arr + n + 1);
	}
	for (int i = 1; i <= n; i++) {
		cout << arr[i] << " ";
	}
	return 0;
}